package io.kiki.sba.registry.api.exchange;

import io.kiki.sba.registry.api.Client;
import io.kiki.sba.registry.api.Server;
import io.kiki.sba.registry.common.model.store.Url;


public interface DataExchanger<T> {
    String SESSION_SERVER_TYPE = "sessionServer";
    String SESSION_SERVER_CONSOLE_TYPE = "sessionServerConsole";
    String DATA_SERVER_TYPE = "dataServer";
    String DATA_SERVER_NOTIFY_TYPE = "dataServerNotify";
    String META_SERVER_TYPE = "metaServer";
    String REMOTE_CLUSTER_META = "remoteMetaServer";
    String REMOTE_DATA_SERVER_TYPE = "remoteDataServer";

    /**
     * connect same type server,one server ip one connection such as different server on data
     * server,serverOne and serverTwo,different type server must match different channelHandlers, so
     * we must connect by serverType,and get Client instance by serverType
     */
    Client connect(String serverType, Url serverUrl, T... channelHandlers);

    /**
     * connect same type server,one server ip one connection such as different server on data
     * server,serverOne and serverTwo,different type server must match different channelHandlers, so
     * we must connect by serverType,and get Client instance by serverType
     *
     * @param serverType
     * @param serverUrl
     * @param connNum         connection number per serverUrl
     * @param channelHandlers
     * @return
     */
    Client connect(String serverType, Url serverUrl, int connNum, T... channelHandlers);

    /**
     * bind server by server port in url parameter,one port must by same server type
     */
    Server open(Url url, T... channelHandlers);

    Server open(Url url, int lowWaterMark, int highWaterMark, T... channelHandlers);

    /**
     * * get Client instance by serverType,very client instance has different channels match different
     * server ip
     */
    Client getClient(String serverType);

    /**
     * get server instance by port
     */
    Server getServer(Integer port);
}
